package com.wh.hotel.dao;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.wh.common.annotation.ResultLog;
import com.wh.common.enums.MethodTypeEnum;
import com.wh.hotel.constants.CommonConstant;
import com.wh.hotel.mapper.HotelRoomTypeCalendarMapper;
import com.wh.hotel.model.HotelRoomTypeCalendar;
import com.wh.hotel.po.PriceHitStrategyPo;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.Date;
import java.util.List;
import java.util.stream.Collectors;

/**
 * @author luweije
 */
@Component
public class HotelRoomTypeCalendarDao {

    @Resource
    private HotelRoomTypeCalendarMapper hotelRoomTypeCalendarMapper;

    @ResultLog(name = "HotelRoomTypeCalendarDao.insertOrUpdate", methodType = MethodTypeEnum.DB)
    public boolean insertOrUpdate(PriceHitStrategyPo hitStrategyPo) {
        return hotelRoomTypeCalendarMapper.insertOrUpdate(hitStrategyPo) >= CommonConstant.SUCCESS_DB;
    }

    @ResultLog(name = "HotelRoomTypeCalendarDao.delete", methodType = MethodTypeEnum.DB)
    public boolean delete(Long roomTypeId, Date sellDate) {
        LambdaQueryWrapper<HotelRoomTypeCalendar> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(HotelRoomTypeCalendar::getRoomTypeId, roomTypeId);
        queryWrapper.eq(HotelRoomTypeCalendar::getSellDate, sellDate);
        return hotelRoomTypeCalendarMapper.delete(queryWrapper) >= CommonConstant.SUCCESS_DB;
    }

    @ResultLog(name = "HotelRoomTypeCalendarDao.selectDistinctSellDate", methodType = MethodTypeEnum.DB, printResult = false)
    public List<Date> selectDistinctSellDate(Long roomTypeId, Date startDt) {
        return hotelRoomTypeCalendarMapper.selectDistinctSellDate(roomTypeId, startDt)
                .stream()
                .map(HotelRoomTypeCalendar::getSellDate)
                .collect(Collectors.toList());
    }
}
